home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_09_04 / 9n04090a < prev    next >
Text File  |  1991-02-04  |  942b  |  31 lines

  1.  
  2.      int DirSort(const void *pItem1, const void *pItem2)
  3.           {
  4.           CHAR ach1[MAXPATH], ach2[MAXPATH];
  5.           register CHAR *psz;
  6.      
  7.      /*
  8.       * Copy the path names to buffers
  9.       */
  10.           strcpy(ach1,((DIR_INFO *)pItem1)->achPathName);
  11.           strcpy(ach2,((DIR_INFO *)pItem2)->achPathName);   
  12.  
  13.      /*
  14.       *   Convert all backslashes (\) to hex 01s.  Since the 
  15.       *   backslash falls in the middle of the valid ASCII 
  16.       *   codes for directory names, it could (and I have 
  17.       *   seen it) cause the strcmp() to wrongly compare two
  18.       *   directories when they are different levels.
  19.       */
  20.       for (psz = ach1; *psz; psz++)
  21.                if (*pse == '\\')
  22.                     *psz = 0x01;
  23.       for (psz = ach2; *psz; psz++)
  24.                if (*psz == '\\')
  25.                     *psz = 0x01;
  26.  
  27.           return(strcmp(ach1,ach2));
  28.      
  29.           }           
  30.  
  31.